<?php
class page extends top
{
	//重定义构造函数
    function __construct(){  
        parent::__construct();
        //定义当前导航
        $this->nav_name = 'page';
        $this->page_title = '专题管理';
        $this->breadcrumb += array('1'=>array('name'=>'专题','url'=>spUrl('page')));

    }
	function index(){
		$data = $this->spArgs();
		//获取当前分类id
		$cat_id = isset($data['cat_id'])?$data['cat_id']:0;
		//构造左侧导航
		$cat_id = $this->__left_nav($cat_id);
		
		if(!is_numeric($cat_id)) $this->__yt_error();
		$this->left_nav_id = $cat_id;
		$this->cat_id =  $cat_id;
		//构造面包屑导航
		$category = spClass("m_category");
		$cat_info  = $category->find(array('id'=>$cat_id));
		if(empty($cat_info)) $cat_info=array('name'=>"全部",'id'=>0);
		$this->breadcrumb += array(
					'2'=>array('name'=>$cat_info['name'],'url'=>spUrl('page','opera',array('cat_id'=>$cat_info['id']))),
        			'3'=>array('name'=>'添加')
        		);

		$page = spClass("m_page");	
		//提交专题
		if($data['submit']){
			if(1){
				$data_insert = array(
					'editor_id'=>$_SESSION['ID'],
					'content'=>$data['content'],
					'description'=>$data['description'],
					'add_time'=>$data['add_time'],
				);
				$is_ok = $page->update('id='.$data['id'],$data_insert);
				if($is_ok){ 
					$this->notice = array('success',$data['update_add'].'成功！');
				}else{
					$data_return = $data;
					$this->notice = array('danger',$data['update_add'].'出错！');
				}
			}else{
				$data_return = $data;
				$this->notice = array('danger','填写有误！');				
			}
		}
		//更新专题
		if(!isset($data_return)){
			$data_return = $page->find(array('cat_id'=>$cat_id));
			if(empty($data_return)) $this->__yt_error();
			$data_return['update_add'] = "更新";
			$data_return['title'] = $cat_info['name'];			
		}
		$breadcrumb = $this->breadcrumb;
		$breadcrumb['3'] = array('name'=>"更新");
		$this->breadcrumb = $breadcrumb;
		$this->data_return = $data_return;
	}	
}